package Service;

import Bean.Flight;
import Bean.Page;
import Dao.FlightDao;
import Utils.DataUtil;

import java.time.LocalDateTime;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张
 * Date: 2025-03-08
 * Time: 21:32
 */
public class FlightService {
    private FlightDao flightDao = new FlightDao();

    public Page selectFlights(int pageNo, int pageSize, String start, String end, String time) {
        System.out.println("[FlightService] 捕获到的数据为 = " + start + " | " + end + " | " + time + " | " + pageNo + " | " + pageSize);
        Page page = new Page();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        LocalDateTime localDateTime = DataUtil.getData(time);
        page.setTotalRecords(flightDao.size(start,end,localDateTime));
        page.setList(flightDao.selectFlights(pageNo,pageSize,start,end,localDateTime));
        return page;
    }

    public Page selectFlights(int pageNo,int pageSize) {
        Page page = new Page();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        page.setTotalRecords(flightDao.size());
        page.setList(flightDao.selectFlights(pageNo,pageSize));
        return page;
    }

    public Flight selectByFlightId(String flightId) {
        Flight flight = new Flight();
        flight.setFlightId(flightId);
        return flightDao.selectByFlightId(flight);
    }

    public boolean update(Flight flight) {
        return flightDao.update(flight);
    }

    public boolean insert(Flight flight) {
        return flightDao.insert(flight);
    }
}
